// 轮播
var mySwiper = new Swiper('.swiper-container1',{
	effect : 'fade',
	fade: {
	  crossFade: true,
	},
	onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
      swiperAnimateCache(swiper); //隐藏动画元素
      swiperAnimate(swiper); //初始化完成开始动画
    },
    onSlideChangeEnd: function(swiper){
      swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
    },
	pagination : '.swiper-pagination',
	paginationClickable: true
})

// 客服浮窗
// $("#chat").on("mouseenter", function() {
// 	$(".chat-one").css('display', 'flex');
// })
// $("#chat").on("mouseleave", function() {
// 	$(".chat-one").hide();
// })
// 客服浮窗
$("#chat").on("click", function(event) {
	$(".chat-one").css('display', 'flex');
})
$("#chat").find('.icon-close').on("click", function(event) {
	$(".chat-one").hide();
    event.stopPropagation()
})

/*点击回到顶部*/
$("#back_top").on("click", function() {
    $('body,html').animate({
        scrollTop: 0
    }, 200);
    return false;
});

$(function (){
    console.log(111);
    //$('#chat').hide();
	var oImg = document.getElementById('image');
	var oname = document.getElementById('name');
	var oQQ = document.getElementById('QQ');
	var phoneTell = document.getElementById('phone_tell');
    var oImg2 = document.getElementById('image2');
    var oname2 = document.getElementById('name2');
    var oQQ2 = document.getElementById('QQ2');
    var phoneTell2 = document.getElementById('phone_tell2');
    var oImg3 = document.getElementById('image3');
	/*
	* 12.24临时写死
	* */
	// phoneTell.innerHTML = '186-6173-1195';
	// oQQ.href = ``;
	// oname.innerHTML = '崔巧艳';
	// oImg.src = 'http://ewei.shop/default/img/index/qrqr.png';

	$.ajax({
		url: 'https://wiki.ewei.shop/api/customer/get',
		success: function (response) {
			$('#chat').show();
			var customer = response.customer
			phoneTell.innerHTML = customer.mobile;
			oQQ.href = `http://wpa.qq.com/msgrd?v=3&uin=${customer.qq}&site=qq&menu=yes`;
			oname.innerHTML = customer.name;
			oImg.src = customer.headimg;
            phoneTell2.innerHTML = customer.mobile;
            oQQ2.href = `http://wpa.qq.com/msgrd?v=3&uin=${customer.qq}&site=qq&menu=yes`;
            oname2.innerHTML = customer.name;
            oImg2.src = customer.headimg;
            oImg3.src = customer.headimg;
		}
	});
})

window.onload = function() {




// 	var arrphone = ['186-6177-2381','158-6554-6761','186-6026-3082'];
// 	var kefuname = ['客户经理：王琦','客户经理：王萱萱','客户经理：张译文'];
// 	var kefuhref = [
// 	'http://wpa.qq.com/msgrd?v=3&uin=3004648558&site=qq&menu=yes',
// 	'http://wpa.qq.com/msgrd?v=3&uin=3003387764&site=qq&menu=yes',
// 	'http://wpa.qq.com/msgrd?v=3&uin=3003335472&site=qq&menu=yes']
// 	var imgcode = [bastPath + 'img/index/codeqi.png',bastPath + 'img/index/codexuan.jpg',bastPath + 'img/index/codehan.jpg'];
//
// //  startMove_scroll();
// //  window.onscroll = startMove_scroll;
// //  window.onresize = startMove_scroll;
//
//     var oImg = document.getElementById('image');
//     var oname = document.getElementById('name');
//     var oQQ = document.getElementById('QQ');
//     var phoneTell = document.getElementById('phone_tell');
//
//     var num = Math.floor(Math.random() * 3);
//     phoneTell.innerHTML = arrphone[num];
//     oQQ.href = kefuhref[num];
//     oname.innerHTML = kefuname[num];
//     oImg.src = imgcode[num];

}
//window.onload = function() {
//
//  startMove_scroll();
//  window.onscroll = startMove_scroll;
//  window.onresize = startMove_scroll;
//
//}

function startMove_scroll() {
    var oDiv = document.getElementById("qq_content");
    var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; //计算目的值
    var len = parseInt((document.documentElement.clientHeight - oDiv.offsetHeight) / 2 + 50 + 'px'); //计算目的值的时候不要带小数
    startMove(scrollTop + len);
}
var timer = null;

function startMove(iTarget) {
    var oDiv = document.getElementById("qq_content");
    clearInterval(timer);
    timer = setInterval(function() {
        var speed = (iTarget - oDiv.offsetTop) / 8;
        speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
        if(oDiv.offsetTop == iTarget) {
            clearInterval(timer);
        } else {
            oDiv.style.top = oDiv.offsetTop + speed + "px";
        }
    }, 10);
}


//联系客服跳转随机客服
function tokefu () {
	var arr = ["http://wpa.qq.com/msgrd?v=3&uin=3001621361&site=qq&menu=yes",
	"http://wpa.qq.com/msgrd?v=3&uin=3003335472&site=qq&menu=yes",
	"http://wpa.qq.com/msgrd?v=3&uin=3003377108&site=qq&menu=yes",
	"http://wpa.qq.com/msgrd?v=3&uin=3004648558&site=qq&menu=yes"]
	var num = Math.floor(Math.random() * 4);
	window.open(arr[num]);
}

// 复制文字
$(".hoverbox1 .flex").on("click",function(){
	$("#inputCopy").text($(this).find("p").text());
	var input = document.getElementById("inputCopy");
	input.select(); // 选中文本
    document.execCommand("copy"); // 执行浏览器复制命令
    $("#inputCopy").text("");
    $("#inputCopy").css("opacity",1);
    setTimeout(function(){
    	$("#inputCopy").css("opacity",0);
    },2000)
})

// 检测是否pc
function browserRedirect() {
	var sUserAgent= navigator.userAgent.toLowerCase();
	var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";
	var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os";
	var bIsMidp= sUserAgent.match(/midp/i) == "midp";
	var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
	var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb";
	var bIsAndroid= sUserAgent.match(/android/i) == "android";
	var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";
	var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";

	if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
//		window.location.href= '手机站链接';
		console.log("shouji");
	} else {
//		window.location.href= 'PC站链接';
		console.log("pc");
	}
}

browserRedirect();
